<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8">
<title>编辑房屋信息</title>
<link rel="stylesheet" href="/css/bootstrap.min.css">
<script src="/js/jquery/jquery.min.js"></script>
<script src="/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
<script src="/js/jquery.validation/1.14.0/messages_zh.min.js"></script>
<style>
input.error {
	border: 1px solid #E6594E;
}
</style>
<script>
	function schange() {
		var i = $('#district_id').val();
		$.ajax({
			url : "/house/allStreetByd.do",
			type : "get",
			data : "district_id=" + i,
			dataType : "text",
			success : function(result) {
				$('#street_id').html(result);
			},
			error : function(msg) {
			}
		})
	};
</script>
</head>
<body>
	<div class="container">
		<form id="editHouseForm">
			<div class="form-group">
				<label for="type_id">请选择房型</label> <select class="form-control"
					id="type_id">
					<option value="" >请选择房型</option>
					<OPTION value=1 <#if "${data.type_id}"==1>selected=selected</#if>>一室一厅</OPTION>
					<OPTION value=2 <#if "${data.type_id}"==2>selected=selected</#if>>两室一厅</OPTION>
					<OPTION value=3 <#if "${data.type_id}"==3>selected=selected</#if>>三室一厅</OPTION>
					<OPTION value=4 <#if "${data.type_id}"==4>selected=selected</#if>>三室两厅</OPTION>
					<OPTION value=7 <#if "${data.type_id}"==7>selected=selected</#if>>两室两厅</OPTION>
					<OPTION value=5 <#if "${data.type_id}"==5>selected=selected</#if>>四室两厅</OPTION>
					<OPTION value=6 <#if "${data.type_id}"==6>selected=selected</#if>>四室三厅</OPTION>
				</select>
			</div>
			<div class="form-group">
				<label for="district_id">请选择区域</label> <select class="form-control"
					id="district_id" onchange="schange()" >
					<option value="" >请选择区域</option>
					<OPTION value=1 <#if "${data.district_id}"==1>selected=selected</#if>>中原区</OPTION>
					<OPTION value=6 <#if "${data.district_id}"==6>selected=selected</#if>>惠济区</OPTION>
					<OPTION value=2 <#if "${data.district_id}"==2>selected=selected</#if>>高新区</OPTION>
					<OPTION value=5 <#if "${data.district_id}"==5>selected=selected</#if>>金水区</OPTION>
					<OPTION value=4 <#if "${data.district_id}"==4>selected=selected</#if>>管城区</OPTION>
					<OPTION value=8 <#if "${data.district_id}"==8>selected=selected</#if>>郑东新区</OPTION>
					<OPTION value=7 <#if "${data.district_id}"==7>selected=selected</#if>>上街区</OPTION>
					<OPTION value=3 <#if "${data.district_id}"==3>selected=selected</#if>>二七区</OPTION>
				</select>
			</div>
			<div class="form-group">
				<label for="street_id">请选择街道</label> <select class="form-control"
					id="street_id"  >
					<option value="" >${data.sname}</option>
				</select>
			</div>

			<div class="form-group">
				<label for="title">标题：</label> <input type="text"
					class="form-control" id="title"  value="${data.title}">
			</div>

			<div class="form-group">
				<label for="price">月租金：</label> <input type="text"
					class="form-control" id="price" 
					value="${data.price}">
			</div>
			<div class="form-group">
				<label for="floorage">面积：</label> <input type="text"
					class="form-control" id="floorage" 
					value="${data.floorage}">
			</div>
			<div class="form-group">
				<label for="contact">联系方式：</label> <input type="text"
					class="form-control" id="contact" 
					value="${data.contact}">
			</div>

			<div class="form-group">
				<label for="describtion">详细信息</label>
				<textarea class="form-control" rows="3" id="description">${data.description}</textarea>
			</div>

			<div class="form-group">
				<button type="button" id="saveBtn" class="btn btn-success">提交</button>
				<button type="button" id="cancelBtn" class="btn btn-default">取消</button>
				<input type="hidden" id="hid" value="${data.id}">
			</div>
		</form>
	</div>
	<script>
		var editHouse = function() {
			$.ajax({
				type : "GET",
				dataType : "json",
				url : "/house/update.do",
				data : {
					"id" : $("#hid").val(),
					"title" : $("#title").val(),
					"contact" : $("#contact").val(),
					"price" : $("#price").val(),
					"description" : $("#description").val(),
					"floorage" : $("#floorage").val(),
					"street_id" : $("#street_id").val(),
					"type_id" : $("#type_id").val()
				},
				success : function(msg) {
					$('#cancelBtn').click();
				},
			});
		}
		$('#saveBtn').on('click', function() {
			editHouse();
		});
		$('#cancelBtn').on('click', function() {
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		});
		
	</script>
</body>
</html>